<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="text" id="txt">
    <script>
    /* 
     onfocus-->获取焦点
     onblur-->失去焦点
    */
    var txt =document.getElementById("txt");
    txt.onfocus = function(){
        this.style.background="pink"
    }
    txt.onblur = function(){
        this.style.background="skyblue";
    }
    </script>
</body>
</html>